package com.twb.system.controller;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.twb.core.base.Result;
import com.twb.core.base.controller.BaseController;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.security.annotation.Auth;
import com.twb.core.util.BeanUtils;
import com.twb.core.util.Results;
import com.twb.system.entity.twbSequence.TwbSequence;
import com.twb.system.entity.twbSequence.dto.GetTwbSequenceByIdDto;
import com.twb.system.entity.twbSequence.dto.SearchTwbSequenceDto;
import com.twb.system.entity.twbSequence.vo.SaveTwbSequenceVo;
import com.twb.system.entity.twbSequence.vo.SearchTwbSequenceVo;
import com.twb.system.entity.twbSequence.vo.UpdateTwbSequenceByIdVo;
import com.twb.system.service.ITwbSequenceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/** 
 * @Title  TwbSequenceController
 * @Description 序列表
 
 * @author DSY
 * @date 2020-12-24 14:55:12
 */ 
@RestController
@RequestMapping("/system/twbSequence")
@Api(tags = "序列表",value="TwbSequenceController")
public class TwbSequenceController extends BaseController{
	@Autowired
	ITwbSequenceService twbSequenceService;
	
	/**
	 * @Title  search
	 * @Description 分页查询
	 * @param vo
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	@Auth(verifyToken = true)
	@GetMapping("/search")
	@ApiOperation(value="分页查询")
	public Result<TwbPageInfo<SearchTwbSequenceDto>> search(SearchTwbSequenceVo vo){
		TwbPageInfo<SearchTwbSequenceDto> result = twbSequenceService.searchTwbSequence(vo);
		return Results.successWithData(result);
	}
	
	/**
	 * @Title  getById
	 * @Description 根据ID获取详情
	 * @param id
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	@Auth(verifyToken = true)
	@GetMapping("/getById")
	@ApiOperation(value="根据ID获取详情")
	public Result<GetTwbSequenceByIdDto> getById(
			@NotBlank
			@RequestParam
			@ApiParam(value="主键",name="id",required=true)
			String id){
		TwbSequence twbSequence = twbSequenceService.getById(id);
		if(twbSequence == null) {
			return Results.failure("数据不存在");
		}
		GetTwbSequenceByIdDto dto = new GetTwbSequenceByIdDto();
		BeanUtils.copyNotNullProperties(twbSequence, dto);
		return Results.successWithData(dto);
	}
	
	/**
	 * @Title  save
	 * @Description 保存信息
	 * @param vo
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	
	@Auth(verifyToken = true)
	@PostMapping("/save")
	@ApiOperation(value="保存信息")
	public Result<String> save(@Valid @RequestBody SaveTwbSequenceVo vo){
		int result = twbSequenceService.saveTwbSequence(vo);
		if(result>0) {
			return Results.success("保存成功");
		}else {
			return Results.failure("保存失败");
		}
	}
	
	
	/**
	 * @Title  updateById
	 * @Description 更新信息
	 * @param vo
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	
	@Auth(verifyToken = true)
	@PutMapping("/updateById")
	@ApiOperation(value="更新信息")
	public Result<String> updateById(@Valid @RequestBody UpdateTwbSequenceByIdVo vo){
		int result = twbSequenceService.updateTwbSequenceById(vo);
		if(result>0) {
			return Results.success("更新成功");
		}else {
			return Results.failure("更新失败");
		}
	}
	
	
	/**
	 * @Title  deleteById
	 * @Description 删除信息
	 * @param id
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	
	@Auth(verifyToken = true)
	@PostMapping("/deleteById")
	@ApiOperation(value="删除信息")
	public Result<String> deleteById(
			@NotBlank
			@RequestParam
			@ApiParam(value="主键",name="id",required=true)
			String id){
		int result = twbSequenceService.deleteTwbSequenceById(id);
		if(result>0) {
			return Results.success("删除成功");
		}else {
			return Results.failure("删除失败");
		}
	}
	
	
	/**
	 * @Title  deleteBatchByIds
	 * @Description 批量删除信息
	 * @param ids
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	
	@Auth(verifyToken = true)
	@PostMapping("/batchDeleteByIds")
	@ApiOperation(value="批量删除信息")
	public Result<String> deleteBatchByIds(
			@NotBlank
			@RequestParam
			@ApiParam(value="主键",name="id",required=true)
			String ids){
		int result = twbSequenceService.deleteTwbSequenceByIds(ids);
		if(result>0) {
			return Results.success("删除成功");
		}else {
			return Results.failure("删除失败");
		}
	}
	
	/**
	 * @Title createCode
	 * @Description 生成编码
	 * @param code
	 * @return
	 * @AuthorOriginally DSY
	 * @date 2022年5月15日 下午8:34:48
	 */
	@Auth(verifyToken = true)
	@PostMapping("/createCode")
	@ApiOperation(value="生成编码")
	public Result<String> createCode(String code){
		String createCode = twbSequenceService.createCode(code);
		return Results.successWithData(createCode);
	}
	
	
	/**
	 * @Title  logicDeleteById
	 * @Description 逻辑删除信息
	 * @param id
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	/*
	@Auth(verifyToken = true)
	@PostMapping("/logicDeleteById")
	@ApiOperation(value = "逻辑删除信息")
	public Result<String> logicDeleteById(
			@NotBlank
			@RequestParam
			String id){
		TwbSequence record = twbSequenceService.get(id);
		if(null == record) {
			return Results.failure("信息不存在");
		}
		record = new TwbSequence();
		record.setId(id);
		twbSequenceService.setUpdateInfo(record);
		record.setIsdel(1);
		int result = twbSequenceService.updateSelective(record);
		if(result>0) {
			return Results.success("删除成功");
		}else {
			return Results.failure("删除失败");
		}
	}
	*/
	
	/**
	 * @Title  logicBatchDeleteByIds
	 * @Description 批量逻辑删除
	 * @param ids
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	/*
	@Auth(verifyToken = true)
	@PostMapping("/logicBatchDeleteByIds")
	@ApiOperation(value = "逻辑删除信息")
	public Result<String> logicBatchDeleteByIds(
			@NotBlank
			@RequestParam
			String ids){
		int result = twbSequenceService.logicBatchDeleteTwbSequenceByIds(ids);
		if(result>0) {
			return Results.success("删除成功");
		}else {
			return Results.failure("删除失败");
		}
	}
	*/
	
	/**
	 * @Title  exportExcel
	 * @Description 导出excel
	 * @param exportExcelVo
	 * @param searchVo
	 * @param request
	 * @return
	 * @author DSY
	 * @date 2020-12-24 14:55:12
	 */
	/*
	@Auth(verifyURL=false)
	@PostMapping("/exportExcel")
	@ApiOperation(value="导出excel")
	public void exportExcel(ExportExcelVo exportExcelVo, SearchTwbSequenceVo searchVo, HttpServletRequest request){
		ExportExcelDto dto = twbSequenceService.exportExcel(request, exportExcelVo, searchVo);
		return Results.successWithData(dto);
	}
	*/
}
